<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include/src :: form_base_js_and_css"/>
</head>
<body style="background-color: #f2f2f2; height: 100%;">

<div id="id_panel">
</div>
<script src="/static/plugins/printWorld/PrintWorld.js"></script>
<script th:inline="javascript">
	var dto = $.parseJSON(JSON.stringify([[${dto}]]));

	// 表单初始化
	var formObj = null;
	//使用layui的sku模块
	layui.config({
		//自定义layui组件的目录,设定扩展的layui模块的所在目录，一般用于外部模块扩展
		base: '/static/js/layui_extends/',
		version: true
	}).use(['form', 'jquery', 'laydate', 'YsForm', 'YsModal'], function(){
		var $ = layui.jquery,
				form = layui.form,
				laydate = layui.laydate,
				YsForm = layui.YsForm,
				YsModal = layui.YsModal;
		/*
		* 表单初始化
		* 参数1：表单配置参数
		* 参数2：子表配置参数
		*/
		formObj = YsForm.init(
				{
					id:'id_panel', // 页面容器ID
					dto: dto
				}
		);

		$('#' + formObj.c.id_header).find('.bg_color_white').find('.layui-inline').append('<button type="button" class="layui-btn layui-btn-normal" id="printing" lay-submit onclick="printingLabels()">打印商品标签</button>');
	});


</script>

<script>
	/**
	 * 打印标签
	 */
	function printingLabels(){
		var sonlist = formObj.c.subGridObj.c.sonlist;

		layui.layer.confirm("确认打印商品标签?",{
			btn: ['确定', '取消']
		}, function (index) {
			if (sonlist.length == 0){
				return layer.alert("子件数据为空,不允许打印商品标签!");
			}
			var dataList = [];
			var vgsbm = formObj.getValueByName("vgsbm");
			var vgsjc = formObj.getValueByName("vgsjc");
			var bid = formObj.getValueByName("bid");
			for(var i=0;i<sonlist.length;i++){

				var data = {
					"companyInfo": vgsbm + "/" + vgsjc,
					"bid":bid,
					"commodityInfo":sonlist[i].allocateNum + "个/" + sonlist[i].subCode + "/" + sonlist[i].subName ,
					"chwInfo":sonlist[i].vck + "/" + sonlist[i].vkq + "/" + sonlist[i].vhw,
				}
				dataList.push(data);
			}
			var json = {};
			json.action = "print"; //打印指令动作。json.action = "preview"，则生成预览。
			// json.template = "https://admintest.mini-ease.com/static/plugins/printWorld/muban/kcLableWsy.fmx"; //模板URL，位于WEB服务器的一个模板文件。
			json.template = window.location.href.split("/web")[0] + "/static/plugins/printWorld/muban/kcLableWsy.fmx"; //模板URL，位于WEB服务器的一个模板文件。
			json.data = dataList;
			json.action = "preview";
			var pw = GetPrintWorld();	//获取打天下对象
			pw.Act(json);
			layer.close(index);
		});
	}
</script>


</body>
</html>